#include <Uefi.h>
#include <Library/BaseLib.h>
#include <Library/IoLib.h>
#include <Library/PcdLib.h>
#include <Library/PciLib.h>
#include <Library/UefiLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/DebugLib.h>
#include <Protocol/S3SaveState.h>



EFI_STATUS
EFIAPI
MyBootScriptEntryPoint (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  EFI_STATUS                  Status;
  EFI_S3_SAVE_STATE_PROTOCOL  *BootScript;
  STATIC CONST UINT8          Info[] = { 0xDE, 0xAD, 0xBE, 0xEF };
  DEBUG((DEBUG_INFO, "---MyBootScriptEntryPoint---\r\n"));
  Status = gBS->LocateProtocol (
                  &gEfiS3SaveStateProtocolGuid,
                  NULL,
                  (VOID **)&BootScript
                  );
  ASSERT_EFI_ERROR (Status);

  Status = BootScript->Write (
                         BootScript,
                         0x0A,
                         (UINT32)sizeof Info,
                         (EFI_PHYSICAL_ADDRESS)(UINTN)&Info
                         );
  ASSERT_EFI_ERROR (Status);
   // Print the contents of BootScript
  DEBUG((DEBUG_INFO, "---Contents of BootScript:---\r\n"));
  DEBUG((DEBUG_INFO, "Address: %p, Size: %d\r\n", BootScript, sizeof(EFI_S3_SAVE_STATE_PROTOCOL)));
  
  // Print the raw data (hexadecimal representation)
  UINT8 *BootScriptData = (UINT8 *)BootScript;
  for (UINTN i = 0; i < sizeof(EFI_S3_SAVE_STATE_PROTOCOL); i++) {
    DEBUG((DEBUG_INFO, "%02X ", BootScriptData[i]));
  }
  DEBUG((DEBUG_INFO, "\r\n"));
  return Status;
}